package com.cskaoyan.service.wx.impl;

import com.cskaoyan.bean.MarketCategory;
import com.cskaoyan.bean.MarketCategoryExample;
import com.cskaoyan.bean.vo.wx.wxcatalogcurrent.WXCatalogCurrentTotalVo;
import com.cskaoyan.bean.vo.wx.wxcatalogindex.WXCatalogIndexTotalVo;
import com.cskaoyan.mapper.MarketCategoryMapper;
import com.cskaoyan.service.wx.WXCatalogIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Yan Dexuan
 * @since 2022/06/29 14:12
 */

@Service
public class WXCatalogIndexServiceImpl implements WXCatalogIndexService {

    @Autowired
    MarketCategoryMapper marketCategoryMapper;

    /**
     * 小程序分类主页，展示商品的一级目录和二级目录。
     * @return com.cskaoyan.bean.vo.wxcatalogindex.WXCatalogIndexTotalVo
     * @author Yan Dexuan
     * @since 2022/06/29 15:18
     */
    @Override
    public WXCatalogIndexTotalVo catalogIndex() {

        //查询一级目录列表。
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = marketCategoryExample.createCriteria();
        criteria.andLevelEqualTo("L1").andDeletedEqualTo(false);

        //获取当前类目为L1的list
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        MarketCategory category = marketCategoryMapper.selectByPrimaryKey(1005000);

        List<MarketCategory> currentL2 =  marketCategoryMapper.selectCurrentL2(category.getId(),"L2");

        /*WXCurrentCategoryVo wxCurrentCategoryVo = new WXCurrentCategoryVo();
        WXCurrentCategoryVo.setWXCurrentCategoryVo(category);*/

        WXCatalogIndexTotalVo totalVo = new WXCatalogIndexTotalVo();

        //当前一级类目信息。
        totalVo.setCurrentCategory(category);

        //类目列表。
        totalVo.setCategoryList(marketCategories);

        //当前二级类目信息。
        totalVo.setCurrentSubCategory(currentL2);

        return totalVo;
    }

    /**
     * 小程序分类主页，显示用户当前点击的一级目录及其对应的二级目录。
 * @param marketCategory
     * @return com.cskaoyan.bean.vo.wxcatalogcurrent.WXCatalogCurrentTotalVo
     * @author Yan Dexuan
     * @since 2022/06/29 19:49
     */
    @Override
    public WXCatalogCurrentTotalVo catalogCurrent(MarketCategory marketCategory) {

        //查询一级目录。
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = marketCategoryExample.createCriteria();
        criteria.andLevelEqualTo("L1");

        //获取List。
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        MarketCategory category2 = marketCategoryMapper.selectByPrimaryKey(marketCategory.getId());

        //查询二级目录。
        List<MarketCategory> list2 = marketCategoryMapper.selectCurrentL2(category2.getId(), "L2");

        WXCatalogCurrentTotalVo totalVo = new WXCatalogCurrentTotalVo();

        totalVo.setCurrentCategory(category2);
        totalVo.setCurrentSubCategory(list2);

        return totalVo;
    }


}
